package com.wwz.frame.common;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description 统一返回格式
 * @Author wwz
 * @Date 2019/07/26
 * @Param
 * @Return
 */
public class ResponseVo extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ResponseVo() {
        put("code", 200);
        put("message", "成功");
    }

    public static ResponseVo error(Integer code, String message) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.put("code", code);
        responseVo.put("message", message);
        return responseVo;
    }

    public static ResponseVo error(CodeEnum codeEnum) {
        return error(codeEnum.getCode(), codeEnum.getMessage());
    }

    public static ResponseVo error(CodeEnum codeEnum, String message) {
        return error(codeEnum.getCode(), message);
    }

    public static ResponseVo error(String message) {
        return error(CodeEnum.SERVER_ERROR, message);
    }

    public static ResponseVo ok() {
        return new ResponseVo();
    }

    public static ResponseVo ok(String message) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.put("message", message);
        return responseVo;
    }

    public static ResponseVo ok(Map<String, Object> map) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.putAll(map);
        return responseVo;
    }

    public ResponseVo put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
